﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GovernmentOfficeProject.LevelDataAccessModel;
using GovernmentOfficeProject.LevelDataAccess;

namespace GovernmentOfficeProject.LevelBusinessLogic
{
    public class BLL_Privilege
    {
        //Entity_SYS_Privilege privilege = null;



        //根据roleID获取对应权限List:
        public List<Entity_SYS_Privilege> getPrivilegeListByRoleID(decimal roleID)
        {
            try
            {
                Entity_SYS_Privilege priEntity = new Entity_SYS_Privilege();
                priEntity.PriMaster = "PER_Role";
                priEntity.PriMasterValue = roleID;
                return new DAL_SYS_Privilege().getPrivilegeListByPrivilegeEntity(priEntity);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        //根据userID获取对应权限List:
        public List<Entity_SYS_Privilege> getPrivilegeListByUserID(decimal userID)
        {
            try
            {
                Entity_SYS_Privilege priEntity = new Entity_SYS_Privilege();
                priEntity.PriMaster = "PER_User";
                priEntity.PriMasterValue = userID;
                return new DAL_SYS_Privilege().getPrivilegeListByPrivilegeEntity(priEntity);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }


        //根据访问类型Master（user/role）、MasterValue(uid/rid)、控制类型Access(menu/button)、AccessValue(mid/bid)、操作权限operation等参数获取数据
        /// <summary>
        /// 根据private条件获取一个private实体,调用处必须确定参数条件最多只返回一行数据.
        /// </summary>
        /// <param name="privilegeEntity"></param>
        /// <returns></returns>
        public Entity_SYS_Privilege getPrivilegeByCondition(Entity_SYS_Privilege privilegeEntity)
        {
            try
            {
                return new DAL_SYS_Privilege().getPrivilegeByPrivilegeEntity(privilegeEntity);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        //根据privilegeID获取一个实体.
        public Entity_SYS_Privilege getPrivilegeByPrivilegeID(decimal privilegeID)
        {
            try
            {
                return new DAL_SYS_Privilege().getPrivilegeByPrivilegeID(privilegeID);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public bool updatePrivilege(decimal priID, Entity_SYS_Privilege priEntity)
        {
            try
            {
                return new DAL_SYS_Privilege().updatePrivilegeByPrivilegeIDAndPrivilegeEntity(priID, priEntity);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public bool addPrivilege(Entity_SYS_Privilege privilegeEntity)
        {
            try
            {
                return new DAL_SYS_Privilege().addPrivilege(privilegeEntity);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public bool deletePrivilege(decimal privilegeID)
        {
            try
            {
                return new DAL_SYS_Privilege().deletePrivilegeByPrivilegeID(privilegeID);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        //根据Master和MasterValue删除多项数据.
        public bool deletePrivilegeByMaster(string strMaster,decimal dclValue)
        {
            try
            {
                return new DAL_SYS_Privilege().deletePrivilegeByMasterAndMasterValue(strMaster, dclValue);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
    }
}
